package com.ruibang.glass.job.entity;


import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Component
@Data
public class DefectDataSource {

    private String username;
    private String password;
    private String url;
    private String driverClass;
    private Resource sqlPath;
    private int batchInsert;
    private int sleepMs;

    public String readSqlFile() {
        String result = null;
        try{
            InputStreamReader isr = new InputStreamReader(sqlPath.getInputStream());
            result = new BufferedReader(isr)
                    .lines().collect(Collectors.joining(System.lineSeparator()));
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }
}
